package com.hcx.poi.xssf.eventmodel.workbookhandler;

import java.util.LinkedList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.hcx.excel.xlsx.SheetInfo;
import com.hcx.xml.sax.ElementContentHandler;

/**
 * 处理 workbook.xml 中 /workbook/sheets/sheet 节点
 * @author 韩朝祥
 *
 */
public class WorkbookSheetHandler implements  ElementContentHandler{
	private List<SheetInfo> sheetInfos = new LinkedList<SheetInfo>();

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes atts) throws SAXException {
		String name = atts.getValue("name");
		String sheetId = atts.getValue("sheetId");
		String rId = atts.getValue("r:id");
		
		SheetInfo info = new SheetInfo(name, Integer.parseInt(sheetId), rId);
		sheetInfos.add(info);
	}

	@Override
	public void endElement(String uri, String localName, String qName,
			String content) throws SAXException {
	}

	@Override
	public boolean isTextElement() {
		return false;
	}

	public SheetInfo[] getSheetInfos(){
		return sheetInfos.toArray(new SheetInfo[sheetInfos.size()]);
	}

	@Override
	public String getHandlePath() {
		return "/workbook/sheets/sheet";
	}
}
